

//module screw(type = 2, r1 = 5, r2 = 7, n = 7, h = 50, t = 16)
module screw(type, r1, r2, n, h, t)
{
	linear_extrude(height = h, twist = 360*t/n, convexity = t)
	difference() {
		circle(r2);
		for (i = [0:n-1]) {
				if (type == 1) rotate(i*360/n) polygon([
						[ 2*r2, 0 ],
						[ r2, 0 ],
						[ r1*cos(180/n), r1*sin(180/n) ],
						[ r2*cos(360/n), r2*sin(360/n) ],
						[ 2*r2*cos(360/n), 2*r2*sin(360/n) ],
				]);
				if (type == 2) rotate(i*360/n) polygon([
						[ 2*r2, 0 ],
						[ r2, 0 ],
						[ r1*cos(90/n), r1*sin(90/n) ],
						[ r1*cos(180/n), r1*sin(180/n) ],
						[ r2*cos(270/n), r2*sin(270/n) ],
						[ 2*r2*cos(270/n), 2*r2*sin(270/n) ],
				]);
		}
	}
}


//module nut(type = 2, r1 = 5.5, r2 = 7.5, r3 = 10, s = 6, n = 7, h = 50/5, t = 16/5)
module nut(type, r1, r2, r3, s, n, h, t)
{
	difference() {
		cylinder($fn = s, r = r3, h = h);
		translate([ 0, 0, -h/2 ]) screw(type, r1, r2, n, h*2, t*2);
	}
}

module madenSchraube(type, r1, r2, n, h, t,schlitzbreite,schlitztiefe)
{
     	difference() 
		{
	  		screw(type, r1, r2, n, h, t);
	  		translate([-r2,-schlitzbreite/2,0])
	    		cube([2*r2,schlitzbreite,schlitztiefe]);
      }
}

module hohlzylinder(aussenradius,innenradius, hoehe)
{
    difference()
    {
	cylinder(h=hoehe, r=aussenradius);
	cylinder(h=hoehe, r=innenradius);
    }
}

module ritzlKopf() {
   linear_extrude(file = "zahnradRitzlKopf.dxf", layer="0", center=true, convexity=10, height=5);
}

module ritzlKopfBegleiter() {
   linear_extrude(file = "zahnradRitzlKopfBegleiter.dxf", layer="0", center=true, convexity=10, height=5);
   translate([0,0,5])
    ritzlKopf();
}

module ritzl(innendurchmesser, aussendurchmesser, schafthoehe, type, r1, r2, n, h, t) {
  translate([0,0,schafthoehe])
   ritzlKopf();
  difference() 
  {   
    hohlzylinder(aussendurchmesser/2,innendurchmesser/2,schafthoehe);
    rotate(a=[0,90,0])
        translate([-r2*1.5,0,0])
	  screw(type, r1, r2, n, h*2, t*2);	
  }
}

//Origbelegung f. V1
//Schraube/Screw
//p1_type = 2; p1_r1 = 5;p1_r2 = 7; 				p1_n=7;		p1_h = 50;	p1_t = 16;
//steigung=p1_h*p1_n/pt1;
//Mutter/Nut
//p2_Type=2;   p2_r1=5.5;p2_r2 =7.5;	p2_r3=10;	p2_s=6;	p2_n=7;		p2_h=50/5;	p2_t=16/5;

//Belegung f. V2
//Schraube/Screw
stdd_h=10;
stdd_t=45;
screwLength=0.6;
p1_type = 2;	p1_r1 = 3.0;	p1_r2 = 3.14;	p1_n = 3;	p1_h = screwLength*stdd_h;	p1_t = screwLength*stdd_t;
schlitzbreite=0.5;
schlitztiefe=1;

//Mutter/Nut
nutLength=0.25;
p2_Type=2;	p2_r1=3.08;	p2_r2=  3.24;	p2_r3=6;	p2_s=6;		
p2_n=p1_n;	p2_h=nutLength*stdd_h;	p2_t=nutLength*stdd_t;
  
translate([ 5, 0, 0 ])
	madenSchraube(p1_type,p1_r1,	p1_r2,	p1_n,	p1_h,	p1_t,schlitzbreite,schlitztiefe);



ritzlInnenDurchmesser=5;
ritzlAussenDurchmesser=10;
schafthoehe=12;
translate([-7,0,0])
  ritzl(ritzlInnenDurchmesser, ritzlAussenDurchmesser, schafthoehe, p2_Type, p2_r1,	p2_r2,	p2_n, 	p2_h,	p2_t);

